/*
 *  $Id: VampiricMoon.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Spells {
    public class VampiricMoon: TargetEnchantmentCard<Creature> {
        public VampiricMoon(): base("001_d_s_vampiric_moon") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Darkness;
            Value = 100;
            Target = CreatureTarget.Own;
            AddManaCost(ElementType.Darkness, 1);
        }

        protected override bool IsPossibleAction(TargetArgs<Creature> args) {
            bool enough = args.Player.GetMana(ElementType.Darkness) >= (args.Target.Damage + 1);
            if (!enough) args.Player.Game.ErrorNotice(ManaCondition.NotEnough.GetText(ElementType.Darkness));
            return enough;
        }

        protected override void DoAction(TargetArgs<Creature> args) {
            args.Player.DecrementMana(ElementType.Darkness, args.Target.Damage);
            base.DoAction(args);
        }
        protected override EnchantmentAffect CreateEnchantment() {
            return new VampiricMoonAffect();
        }

        private class VampiricMoonAffect: EnchantmentAffect<VampiricMoon> {
            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnHit += DoHit;
            }

            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnHit -= DoHit;
            }

            private void DoHit(Creature hitter, AbstractObject target, int damage) {
                if (hitter != Owner && target is Creature && damage > 1)
                    Owner.HealBy(NewDamage(DamageType.Regeneration, damage-1));
            }
        }
    }
}
